use hypers::prelude::*;
use hypers::tracing::info;

async fn hello(req: Request) -> &'static str {
    let http_version = req.version();
    println!("http_version = {:?}", http_version);
    "Hello World"
}

#[tokio::main]
async fn main() -> Result<()> {
    tracing_subscriber::fmt().init();
    let mut root = Router::default();
    root.get("/hello", hello);
    info!("root = {:#?}", root);
    let tls = NativeTls::from_pkcs12(include_bytes!("../certs/identity.p12"), "mypass")?;
    // https://127.0.0.1:7878/hello
    let listener = hypers::TcpListener::bind("127.0.0.1:7878").await?;
    let listener = NativeTlsListener::new(listener, tls)?;
    hypers::listen(root, listener).await
}

